/* 
 * File:   Editor.cpp
 * Author: agu
 * 
 * Created on 4 de junio de 2014, 18:18
 */
#include <iostream>
#include "editor_Editor.h"
#include "editor_NuevaCampania.h"

Editor::Editor(Glib::RefPtr<Gtk::Application> aplicacion) {
    this->app = aplicacion;
    //Load the GtkBuilder file and instantiate its widgets:
    this->builder = Gtk::Builder::create();
    try {
        this->builder->add_from_file("gladeInterfaces/editor.glade");
    } catch (const Glib::FileError& ex) {
        std::cout << "FileError: " << ex.what() << std::endl;

    } catch (const Glib::MarkupError& ex) {
        std::cout << "MarkupError: " << ex.what() << std::endl;

    } catch (const Gtk::BuilderError& ex) {
        std::cout << "BuilderError: " << ex.what() << std::endl;

    }
    this->loadWidgets();
    this->connectWidgets();
}

void Editor::loadWidgets() {
    this->builder->get_widget("window", this->window);
    this->builder->get_widget("button_new", this->button_new);
    this->builder->get_widget("button_del", this->button_del);
    this->builder->get_widget("button_quit", this->button_quit);
    //this->builder->get_widget("button_mod", this->button_mod);

}

void Editor::connectWidgets() {
    this->window->signal_hide().connect(sigc::mem_fun(this, &Editor::close));
    this->button_quit->signal_clicked().connect(sigc::mem_fun(this, &Editor::close));
    this->button_new->signal_clicked().connect(sigc::mem_fun(this, &Editor::newCampaign));
    this->button_del->signal_clicked().connect(sigc::mem_fun(this, &Editor::deleteCampaign));
    //this->button_mod->signal_clicked().connect(sigc::mem_fun(this, &Editor::editCampaign));
}

Editor::~Editor() {
    delete window;
}

void Editor::close() {
    this->window->close();
}

void Editor::newCampaign() {
    newCamp.run();
}

void Editor::deleteCampaign() {
    this->delCamp.setWindowsBack(this->window);
    this->delCamp.run();
}

void Editor::run() {
    app->run(*this->window);
}

void Editor::editCampaign() {
//    this->listCamp.setWindowsBack(this->window);
//    this->listCamp.run();
}
